//
//  GoodsReleasedNavBar.m
//  BestPurchase
//
//  Created by ZSMAC on 2018/10/16.
//  Copyright © 2018年 张帅. All rights reserved.
//

#import "GoodsReleasedNavBar.h"
@interface GoodsReleasedNavBar ()
@property(nonatomic,strong)MCustomButton *backBtn;
@property(nonatomic,strong)UILabel * titleLabel;
@property(nonatomic,strong)UIButton * typeBtn;
@property(nonatomic,retain)UIView * line;
@end
@implementation GoodsReleasedNavBar

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self uiSrt];
    }
    return self;
}
- (void)uiSrt {
    _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, StatusBar_Rect.size.height, SCREEN_WIDTH, NavBarHeight-StatusBar_Rect.size.height)];
    _titleLabel.font=Font(17);
    _titleLabel.textAlignment=NSTextAlignmentCenter;
    _titleLabel.textColor=[UIColor whiteColor];
    _titleLabel.text=@"添加商品";
    [self addSubview:_titleLabel];
    
    _backBtn = [MCustomButton buttonWithType:UIButtonTypeCustom];
    _backBtn.frame=CGRectMake(15, self.height-40, 35, 35);
    _backBtn.imageRect=CGRectMake(_backBtn.width/4,_backBtn.height/4, 15, 15);
    [_backBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
    _backBtn.backgroundColor=[[UIColor blackColor] colorWithAlphaComponent:0.5];
    _backBtn.layer.cornerRadius=_backBtn.width/2;
    _backBtn.layer.masksToBounds=YES;
    _backBtn.titleLabel.font=Font(13);
    [_backBtn addTarget:self action:@selector(backBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_backBtn];
    
    _typeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _typeBtn.titleLabel.font=Font(15);
    _typeBtn.frame=CGRectMake(self.width-50, StatusBar_Rect.size.height, 50, NavBarHeight-StatusBar_Rect.size.height);
    [_typeBtn setTitleColor:themeColor forState:UIControlStateNormal];
    [_typeBtn addTarget:self action:@selector(typeBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_typeBtn];
   
    
}
- (void)setTypeStr:(NSString *)typeStr {
    _typeStr=typeStr;
    [_typeBtn setTitle:_typeStr forState:UIControlStateNormal];
}
- (void)setCurrentAlpha:(CGFloat)currentAlpha {
    _currentAlpha=currentAlpha;
    if (_currentAlpha<1) {
        _titleLabel.textColor=[[UIColor whiteColor] colorWithAlphaComponent:_currentAlpha];
        [_typeBtn setTitleColor:[themeColor colorWithAlphaComponent:1-_currentAlpha] forState:UIControlStateNormal];
        self.backgroundColor =[themeColor colorWithAlphaComponent:_currentAlpha];
        _line.backgroundColor=[[UIColor groupTableViewBackgroundColor] colorWithAlphaComponent:_currentAlpha];
        _backBtn.backgroundColor=[_backBtn.backgroundColor colorWithAlphaComponent:(1-_currentAlpha)-0.5];
      
    }else {
         _titleLabel.textColor=[UIColor whiteColor];
        [_typeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.backgroundColor =[themeColor colorWithAlphaComponent:_currentAlpha];
    }
    
}
- (void)typeBtnClicked:(UIButton *)btn {
    [self selectedType];
}
- (void)selectedType {
    @WeakObj(self);
    UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请选择商品种类(必选)" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        [[MPublicManager sharedPublicManager].currentControllr.navigationController popViewControllerAnimated:YES];
    }];
    [alert addAction:cancelAction];
    NSArray *types = @[@"百货",@"女装",@"男装",@"鞋包",@"电器",@"家装",@"其他",];
    for (NSString *typeStr in types) {
        UIAlertAction * action = [UIAlertAction actionWithTitle:typeStr style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            if (selfWeak.setectTypeBlock) {
                [selfWeak.typeBtn setTitle:action.title forState:UIControlStateNormal];
                selfWeak.setectTypeBlock(action.title);
            }
        }];
        [alert addAction:action];
    }
    [[MPublicManager sharedPublicManager].currentControllr presentViewController:alert animated:YES completion:nil];

}
- (void)backBtnClicked:(UIButton *)btn {
    [[MPublicManager sharedPublicManager].currentControllr.navigationController popViewControllerAnimated:YES];
}





@end
